# -*- coding: utf-8 -*-
# This code written by ChanGOGOGO
"""
PET - 获取场景列表
"""
import sys
import os

current_script_dir = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.dirname(current_script_dir)
if parent_dir not in sys.path:
    sys.path.append(parent_dir)
from callplus_api import OpenAPI
from util import *

"""接口调用"""
open_api = OpenAPI(env="dev")
# 查询场景列表
res = open_api.get_template_list()

"""根据场景名称获取场景ID"""
target_scene_name = "CAPS-A"
res_code = res["code"]
if res_code == 0:
    scene_list = res["data"]
    if len(scene_list) == 0:
        logging.warning(f"该业务下没有场景！")
    else:
        for scene in scene_list:
            scene_name = scene["templateName"]
            if target_scene_name == scene_name:
                scene_id = scene["templateId"]
                logging.info(f"目标场景【{scene_name}】的ID：{scene_id}")
                break
        else:
            logging.warning(f"该业务下没有名称为{target_scene_name}的场景！")
else:
    logging.warning(f"查询场景列表失败！")
